/** @jsxImportSource @emotion/react */
import * as React from "react";
import {BlobInputList, CCell, Cell, Table, TableBody, TableRow, Text,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {usePrefixDataEdit, usePrefixDataTable} from "../../hook/usePrefixData";
import {DirectLink} from "../../../routing/Link";
import {TailMenRowIspCheck} from "../../contain/rarelyVary";

//【配置模式】 ['内径差', {t: '筒体同一断面上最大内径与最小内径差', pr: '几何尺寸检验', span: 5,u:'mm'}],
//模型参考： [[desc, name, cb], add2p]: any, i: number)
//pr前缀只能继承同一个列的前面几个连续同样设置的行的配置。 左边和右边两半列区是独立的。 或者设置pr:null就是去掉该前缀影响范围或者不是{}的标题也自动去掉继承性前缀。
export const config资料审查 = [
    [['设计单位', '_$设计单位'], ['设计日期', '_$设计日期'], ],
    [['产品标准', '_$产品标准'], ['容器图号', '_$设计图号'], ],
    [['设计使用年限', '_$设计年限', '年'], ['产品编号', '_$出厂编号'] ],
    [['制造单位', '_$制造单位'], ['制造日期', '_$制造日期'], ],
    [['安装单位', '_$安装单位'], ['投入使用日期', '_$投用日期'], ],
    [[{pr:'结构型式', span:2, t:'主体结构型式'}, '_$主体结构'], ['安装型式', '_$安装型式'] ],
    [[{t:'支座型式'}, '_$支座型式'], ['保温绝热方式', '_$保温绝热方式'] ],
    //【拆分点】     orc.是换热? '换热面积':'容积'}
    [['容积', '_$容积换热', 'm³'], ['球罐内径', '_$内径', 'mm'],  ],
    //允许充装量 =  (pa?.充重);  //.充重(Tool.castFloat(pms.getLoadweight()))
    [['球罐高', '_$外形高长','mm'], ['最大充许充装量', {n:'_$允许充装量',u:'kg'},] ],
    //在前面结论页概况已经录入的：_$设计温
    [['设计压力', '_$设计压力', 'MPa'], ['工作压力', '_$工作压力','MPa'], ],
    [['设计温度',{n:'_$设计温', u:'℃'}], ['工作温度', '_$工作温度','℃'], ],
    [['腐蚀裕度', '_$腐蚀裕量', 'mm'], ['介质', '_$工作介质',],  ],
    [['材质', '材质'], ['厚度', '厚度', 'mm'], ],
];

export const MaterialReview=
React.forwardRef((
    { children, show ,alone=true,redId,nestMd,label}:InternalItemProps,  ref
) => {
    const {inp, setInp} = useItemInputControl({ref});
    const [renderEditor, itemA审查概况] = usePrefixDataEdit({
                               inp, setInp, config: config资料审查,  });
    const [getInpFilter] = useMeasureInpFilter(null, itemA审查概况, );
    return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                nestMd={nestMd} alone={alone} label={label!}>
        <Text variant="h5">{label}：</Text>
        资料审查设备概况除在台账业务信息中可修改外还需修改的部分:
        {renderEditor}
        { children }
    </InspectRecordLayout>;
});

export const itemA上次问题: string[]=['资料审查','上次缺处'];
export const PreviousQuestion=
    React.forwardRef((
        { children, show ,alone=true,redId,nestMd,label}:InternalItemProps,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null,itemA上次问题,);
        const {inp, setInp} = useItemInputControl({ ref });
        return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                    nestMd={nestMd} alone={alone} label={label!}>
            <Text variant="h5">{label}：</Text>
            资料审查情况：
            <BlobInputList value={inp?.资料审查 || ''} rows={6} datalist={['资料基本齐全。']}
                           onListChange={v => setInp({...inp, 资料审查: v || undefined})}/>
            <br/>
            上次定期检验问题记载：
            <BlobInputList value={inp?.上次缺处 || ''} rows={6} datalist={['上次年度检验报告编号：  ， 检验机构： 特种设备检测研究院。']}
                           onListChange={v => setInp({...inp, 上次缺处: v || undefined})}/>
        </InspectRecordLayout>;
});

const config资料审查上 = config资料审查.slice(0, 7);
const config资料审查下 = config资料审查.slice(7);
export const MaterialReviewVw = ({theme, orc, rep}: { theme: any, orc: any, rep: any }
) => {
    //【表格助手】  JSON.parse(orc?._tblFixed??'[]')  ; 【制表工具】  直接替换目标表的fixed字段 ：动态开发测试的
    const renderUpper = usePrefixDataTable({config: config资料审查上, orc, rep, slash: true});
    const renderMiddle = usePrefixDataTable({
        config: config资料审查下, orc, rep, slash: true,
        embed: {0: <CCell split rowSpan={6}>性能参数</CCell>,},
    });
    return <>
        <div css={{"@media print": {paddingBottom: '4.5rem', pageBreakInside: 'avoid'}}}>
            <Text id='MaterialReview' variant="h2" css={{textAlign: 'center', marginTop: '1rem',
            }}>球形储罐资料审查报告</Text>
            <div css={{display: 'flex', justifyContent: 'space-between'}}>
                <Text></Text>
                <Text>报告编号：{rep.isp.no}</Text>
            </div>
        </div>
        <Table fixed={ ["4.2%", "12.1%", "44%", "6%", "6.4%", "%"] }  tight miniw={800}
                            css={{borderCollapse: 'collapse', "@media print": {marginTop: '-4.5rem'}}}>
            <TableBody>
                <DirectLink
                    href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/MaterialReview#MaterialReview`}>
                    {renderUpper}
                </DirectLink>
            </TableBody>
        </Table>
        <Table fixed={ ["4.2%", "4%", "8.2%", "39%", "4%", "10.2%", "%"] }
                                   css={{borderCollapse: 'collapse',}} tight miniw={800}>
            <TableBody>
                <DirectLink
                    href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/MaterialReview#MaterialReview`}>
                    {renderMiddle}
                </DirectLink>
            </TableBody>
        </Table>
        <Table fixed={["8.1%", "%"]} css={{borderCollapse: 'collapse'}} tight miniw={800}>
            <TableBody>
                <DirectLink
                    href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/PreviousQuestion#PreviousQuestion`}>
                    <TableRow>
                        <CCell>资料审查情况</CCell>
                        <Cell split={true} colSpan={4}>
                            <div css={{minHeight: '3rem', whiteSpace: 'pre-wrap'}}>
                                {orc.资料审查 || '／'}
                            </div>
                        </Cell>
                    </TableRow>
                    <TableRow>
                        <CCell>上次定期检验问题记载</CCell>
                        <Cell split={true} colSpan={4}>
                            <div css={{minHeight: '3rem', whiteSpace: 'pre-wrap'}}>
                                {orc.上次缺处 || '／'}
                            </div>
                        </Cell>
                    </TableRow>
                </DirectLink>
            </TableBody>
        </Table>
        <TailMenRowIspCheck orc={orc} rep={rep}
                            href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/ProjectList#ProjectList`}>
        </TailMenRowIspCheck>
    </>;
};
